<?php
namespace app;

use app\util\Mysql;

/**
 * tinymeng
 */
class Controller{

    public $check_user = true;//是否验证用户登录：true验证登录 false不验证登录
    public $restrictAccess = false;//是否限制访问：true限制访问，false不限制访问
    public $database;
    public $userInfo;

    /**
     * tinymeng
     * __construct
     */
    public function __construct(){
        if((!defined("MODEL") || MODEL!='install')) {
            //初始化数据库
            $this->database = Mysql::init();
        }


        //验证用户登录
        if($this->check_user){
            $this->checkLogin();
        }
        //验证接口签名等。。。
    }

    /**
     * 验证登录
     * @return void
     */
    public function checkLogin(){
        if ($_SESSION['username'] == '' || isset($_SESSION["username"]) == false) {
            echo "<script>alert('当前未登录!');window.location.href='/?c=login';</script>";
            exit();
        }
        $this->userInfo = $_SESSION['userInfo'];
    }


}
